package com.oa.admin.controller;

import com.joneying.common.web.response.Resp;
import com.oa.admin.dto.PhotoAlbumAddDTO;
import com.oa.admin.entity.PhotoAlbum;
import com.oa.admin.service.IPhotoAlbumService;
import com.oa.admin.vo.PhotoAlbumListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.joneying.common.annotation.CommonController;
import org.springframework.context.annotation.Description;

import java.util.List;

import org.springframework.web.bind.annotation.RestController;
import com.oa.core.BaseController;

/**
 * @author syb123
 * @since 2019-01-22
 */
@RestController
@RequestMapping("/photoAlbum")
@Api(description = "相册表模块")
public class PhotoAlbumController extends BaseController {

    private final IPhotoAlbumService photoAlbumService;

    @Autowired
    public PhotoAlbumController(IPhotoAlbumService photoAlbumService) {
        this.photoAlbumService = photoAlbumService;
    }

    /**
     * 查询列表
     *
     * @param page  页码
     * @param limit 每页多少条
     * @return Resp
     */
    @GetMapping("/list")
    @CommonController
    @Description("查询所有")
    @ApiOperation(value = "查询")
    public Resp<List<PhotoAlbumListVO>> findList(
            @ApiParam(value = "页码") @RequestParam(required = false) Integer page,
            @ApiParam(value = "查询条数") @RequestParam(required = false) Integer limit) {
        return new Resp().success(photoAlbumService.findList(page, limit));
    }


    /**
     * 新增
     *
     * @param photoAlbumAddDTO PhotoAlbumAddDTO
     * @return Resp
     */
    @PostMapping("")
    @CommonController
    @Description("新增")
    @ApiOperation(value = "新增")
    public Resp add(@ApiParam(value = "相册表对象") @RequestBody(required = false) PhotoAlbumAddDTO photoAlbumAddDTO) {
        return photoAlbumService.add(photoAlbumAddDTO);
    }

    @DeleteMapping("/{id}")
    @CommonController
    @Description("删除")
    @ApiOperation(value = "删除")
    public Resp del(@PathVariable String id){
        return photoAlbumService.del(id);
    }

}
